package cn.iocoder.yudao.module.member.controller.admin.faceanalyseresult;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.member.controller.admin.faceanalyseresult.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.faceanalyseresult.FaceanalyseResultDO;
import cn.iocoder.yudao.module.member.service.faceanalyseresult.FaceanalyseResultService;

@Tag(name = "管理后台 - 会员皮肤状态分析结果")
@RestController
@RequestMapping("/member/faceanalyse-result")
@Validated
public class FaceanalyseResultController {

    @Resource
    private FaceanalyseResultService faceanalyseResultService;

    @PostMapping("/create")
    @Operation(summary = "创建会员皮肤状态分析结果")
    @PreAuthorize("@ss.hasPermission('member:faceanalyse-result:create')")
    public CommonResult<Long> createFaceanalyseResult(@Valid @RequestBody FaceanalyseResultSaveReqVO createReqVO) {
        return success(faceanalyseResultService.createFaceanalyseResult(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新会员皮肤状态分析结果")
    @PreAuthorize("@ss.hasPermission('member:faceanalyse-result:update')")
    public CommonResult<Boolean> updateFaceanalyseResult(@Valid @RequestBody FaceanalyseResultSaveReqVO updateReqVO) {
        faceanalyseResultService.updateFaceanalyseResult(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除会员皮肤状态分析结果")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('member:faceanalyse-result:delete')")
    public CommonResult<Boolean> deleteFaceanalyseResult(@RequestParam("id") Long id) {
        faceanalyseResultService.deleteFaceanalyseResult(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除会员皮肤状态分析结果")
                @PreAuthorize("@ss.hasPermission('member:faceanalyse-result:delete')")
    public CommonResult<Boolean> deleteFaceanalyseResultList(@RequestParam("ids") List<Long> ids) {
        faceanalyseResultService.deleteFaceanalyseResultListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得会员皮肤状态分析结果")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('member:faceanalyse-result:query')")
    public CommonResult<FaceanalyseResultRespVO> getFaceanalyseResult(@RequestParam("id") Long id) {
        FaceanalyseResultDO faceanalyseResult = faceanalyseResultService.getFaceanalyseResult(id);
        return success(BeanUtils.toBean(faceanalyseResult, FaceanalyseResultRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得会员皮肤状态分析结果分页")
//    @PreAuthorize("@ss.hasPermission('member:faceanalyse-result:query')")
    public CommonResult<PageResult<FaceanalyseResultRespVO>> getFaceanalyseResultPage(@Valid FaceanalyseResultPageReqVO pageReqVO) {
        PageResult<FaceanalyseResultRespVO> pageResult = faceanalyseResultService.getFaceanalyseResultPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, FaceanalyseResultRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出会员皮肤状态分析结果 Excel")
    @PreAuthorize("@ss.hasPermission('member:faceanalyse-result:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportFaceanalyseResultExcel(@Valid FaceanalyseResultPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<FaceanalyseResultRespVO> list = faceanalyseResultService.getFaceanalyseResultPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "会员皮肤状态分析结果.xls", "数据", FaceanalyseResultRespVO.class,
                        BeanUtils.toBean(list, FaceanalyseResultRespVO.class));
    }

}